package xin.val1ant.demo_idea_community.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import xin.val1ant.demo_idea_community.entity.Admin;
import xin.val1ant.demo_idea_community.repository.AdminRepository;

import java.util.List;

@Service
public class AdminServiceImpl implements IAdminService,UserDetailsService {

    @Autowired
    private AdminRepository adminRepository;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        Admin admin = adminRepository.findByUsername(s);
//        return new User(admin.getUsername(),admin.getPassword(),admin.getAuthorities());
        return admin;
    }

    @Override
    public List<Admin> listAdmins() {
        List<Admin> admins = adminRepository.findAll();
        return admins;
    }
}
